﻿class Point3D {
	public var focusLength:Number = 250;
	public var x:Number = 0;
	public var y:Number = 0;
	public var z:Number = 0;
	private var vpX:Number = 0;
	private var vpY:Number = 0;
	private var cX:Number = 0;
	private var cY:Number = 0;
	private var cZ:Number = 0;
	public function Point3D(x:Number, y:Number, z:Number) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	public function setVanishingPoint(vpX:Number, vpY:Number):Void {
		this.vpX = vpX;
		this.vpY = vpY;
	}
	public function setCenter(cX:Number, cY:Number, cZ:Number):Void {
		this.cX = cX;
		this.cY = cY;
		this.cZ = cZ;
	}
	public function get scale():Number {
		return focusLength/(focusLength+z+cZ);
	}
	public function get screenX():Number {
		return vpX+(cX+x)*scale;
	}
	public function get screenY():Number {
		return vpY+(cY+y)*scale;
	}
	public function rotateX(angle:Number):Void {
		var cos:Number = Math.cos(angle);
		var sin:Number = Math.sin(angle);
		var y1:Number = y*cos-z*sin;
		var z1:Number = z*cos+y*sin;
		y = y1;
		z = z1;
	}
	public function rotateY(angle:Number):Void {
		var cos:Number = Math.cos(angle);
		var sin:Number = Math.sin(angle);
		var x1:Number = x*cos-z*sin;
		var z1:Number = z*cos+x*sin;
		x = x1;
		z = z1;
	}
	public function rotateZ(angle:Number):Void {
		var cos:Number = Math.cos(angle);
		var sin:Number = Math.sin(angle);
		var x1:Number = x*cos-y*sin;
		var y1:Number = y*cos+x*sin;
		x = x1;
		y = y1;
	}
}
